package com.zhen.netty.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author zhen-desktop
 * @version 2017/4/2
 * @description
 */
public class TimerServer {

    public static void main(String[] args) {
        int port = 9999;
        if(args != null & args.length > 0){
            try {
                port = Integer.valueOf(args[0]);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        ServerSocket server = null;
        try {
            server = new ServerSocket(port);
            System.out.println("Timeserver start on :" + port);
            Socket socket = null;
            while (true){
                socket = server.accept();
                new Thread(new TimeServerHandler(socket)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(server != null){

                try {
                    server.close();
                    server = null;
                    System.out.println("TimeServer stop!");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
